package Dao;

import DB.DBConnection;
import pojo.Vip;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class VipDao {

    public static Vip viplogin(String vip_name) {
        String sql = "SELECT * FROM vip WHERE vip_name =? ";
        try (Connection connection = DBConnection.getConnection();
             PreparedStatement statement = connection.prepareStatement(sql)) {
            statement.setString(1, vip_name);
            ResultSet resultSet = statement.executeQuery();
            if (resultSet.next()) {
                int vip_id= resultSet.getInt("vip_id");
                return new Vip(vip_id,vip_name);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public void addVip(Vip vip) {
        String sql = "INSERT INTO vip (vip_name) VALUES (?)";
        try (Connection connection = DBConnection.getConnection();
             PreparedStatement statement = connection.prepareStatement(sql)) {
            statement.setString(1, vip.getVip_name());
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


}
